﻿
@{
    ViewBag.Title = "Cart";
}

@using eCommerce.Core.Domain.Products
@model eCommerce.Controllers.ShoppingCartModel
<h2>Cart</h2>


<div class="row-fluid">

    <div class="span4">
        <table class="table table-hover">
            <thead>
                <tr>
                    <th>#</th>
                    <th>Product</th>
                    <th>UnitPrice</th>
                    <th>Quantity</th>
                    <th>Subtotal</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
               @{
                   var itemIndex = 0;
               }
             @foreach (var cartItem in Model.Items)
             {
                 <tr>
                    <td>

                        <span>@(itemIndex+1)</span>
                    </td>
                     <td>
                         <img src="@cartItem.PictureUrl"/>
                         <span>@cartItem.ProductName <br/>@cartItem.AttributeInfo</span>
                     </td>
                    <td>
                        <span>@cartItem.UnitPrice</span>
                    </td>
                    <td>
                        <span>@cartItem.Quantity</span>
                    </td>
                     <td><span>@cartItem.SubTotal</span></td>
                    <td>
                        <span class="glyphicon glyphicon-remove removebtn" data="@cartItem.Id"></span>
                    </td>
                </tr>
                 itemIndex++;

             }
            </tbody>
        </table>
        <table class="table">
            <tr class="success">
                <td>
                    Total: <span >@Model.Total </span>
                </td>
                <td>
                    <button class="btn btn-primary sendOrder" type="button" >Send Order</button>
                </td>
            </tr>
        </table>

    </div>
</div>


@section scripts{
    <script>
        $(document).ready(function() {
            $('.sendOrder').click(function() {
                location.href = "/checkout";
            });
            $('.removebtn').click(function() {
                var shoppingCartItemId = $(this).attr("data");

                var jsObj = {
                    ShoppingCarItemId: shoppingCartItemId
                };
                $.ajax({
                    //url: "/Product/BatchUpdateInitProduct2",
                    url: "/api/ShoppingCartApi/RemoveFromCart",
                    type: 'post',

                    data: ko.toJSON(jsObj),
                    contentType: 'application/json',
                    success: function(result) {
                        if (result.Status == "0") {


                            //$('#productcount').html(result.Message);
                            //$('#message').show();
                            alert("删除成功");

                        } else {
                            alert(result.Message);
                        }
                    }
                });
            });
        });
    </script>
}